<template>
  <view><!-- <u-button @click="pay">立即支付</u-button> --></view>
</template>

<script>
import { getInfo } from '@/api/go.js';
export default {
  data() {
    return {
      key: ''
    };
  },
  methods: {
    async pay() {
      const res = await getInfo(this.key);
      // this.hideLoading();
      uni.hideLoading();
      const { data } = res;
      const { state, url, code } = data;
      if (state == 'ok') {
        window.location.href = url;
      } else if (code == 'paid') {
        uni.showModal({
          title: '提示',
          content: '订单已支付',
          showCancel: false
        });
      } else if (code == '404') {
        uni.showModal({
          title: '提示',
          content: '订单已过期',
          showCancel: false
        });
      } else {
        uni.showModal({
          title: '提示',
          content: '支付失败',
          showCancel: false
        });
      }
    }
  },
  onLoad(options) {
    this.key = options.key;
    // this.init();

    uni.showLoading({
      title: '正在唤起支付...',
      mask: true
    });
    setTimeout(() => {
      this.pay();
    }, 1500);
  }
};
</script>

<style></style>
